package com.ruoyi.system.service.honor.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.honor.student.GraduateStudent;
import com.ruoyi.system.domain.honor.student.GraduateStudentEducation;
import com.ruoyi.system.mapper.honor.GraduateStudentEducationMapper;
import com.ruoyi.system.mapper.honor.GraduateStudentMapper;
import com.ruoyi.system.service.honor.IGraduateStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.ruoyi.common.utils.SecurityUtils.getUserId;

/**
 * 代性毕业生信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-01
 */
@Service
public class GraduateStudentServiceImpl implements IGraduateStudentService
{
    @Autowired
    private GraduateStudentMapper graduateStudentMapper;
    @Autowired
    private GraduateStudentEducationMapper graduateStudentEducationMapper;

    /**
     * 查询代性毕业生信息
     * 
     * @param id 代性毕业生信息主键
     * @return 代性毕业生信息
     */
    @Override
    public GraduateStudent selectGraduateStudentById(Long id)
    {
        //List<GraduateStudentEducation> educationList = graduateStudentEducationMapper.selectGraduateStudentEducationListByStudentId(id);
        GraduateStudent graduateStudent = graduateStudentMapper.selectGraduateStudentById(id);
        //graduateStudent.setEducationList(educationList);
        return graduateStudent;
    }

    /**
     * 查询代性毕业生信息列表
     * 
     * @param graduateStudent 代性毕业生信息
     * @return 代性毕业生信息
     */
    @Override
    public List<GraduateStudent> selectGraduateStudentList(GraduateStudent graduateStudent)
    {
        //如果是老师，则只显示自己上传的
        if(graduateStudent.getCurrentRole()!=null&&graduateStudent.getCurrentRole().equals("teacher")){
            graduateStudent.setTeacherId(getUserId());
        }
        //如果是部门，则显示老师是系里的所有
        if(graduateStudent.getCurrentRole()!=null&&graduateStudent.getCurrentRole().equals("department")){
            graduateStudent.setDeptId(SecurityUtils.getDeptId());
        }
        List<GraduateStudent> graduateStudentList = graduateStudentMapper.selectGraduateStudentList(graduateStudent);
//        for (GraduateStudent graduateStudent1 : graduateStudentList) {
//            List<GraduateStudentEducation> educationList = graduateStudentEducationMapper.selectGraduateStudentEducationListByStudentId(graduateStudent1.getId());
//            graduateStudent1.setEducationList(educationList);
//        }
        return graduateStudentList;
    }

    /**
     * 新增代性毕业生信息
     * 
     * @param graduateStudent 代性毕业生信息
     * @return 结果
     */
    @Override
    public int insertGraduateStudent(GraduateStudent graduateStudent)
    {
        int result = graduateStudentMapper.insertGraduateStudent(graduateStudent);
//        if (result==1) {
//            List<GraduateStudentEducation> educationList = graduateStudent.getEducationList();
//            if (educationList != null && !educationList.isEmpty()) {
//                for (GraduateStudentEducation education : educationList) {
//                    education.setStudentId(graduateStudent.getId());
//                    graduateStudentEducationMapper.insertGraduateStudentEducation(education);
//                }
//            }
//        }
        return result;
    }

    /**
     * 修改代性毕业生信息
     * 
     * @param graduateStudent 代性毕业生信息
     * @return 结果
     */
    @Override
    public int updateGraduateStudent(GraduateStudent graduateStudent)
    {
        return graduateStudentMapper.updateGraduateStudent(graduateStudent);
    }

    /**
     * 批量删除代性毕业生信息
     * 
     * @param ids 需要删除的代性毕业生信息主键
     * @return 结果
     */
    @Override
    public int deleteGraduateStudentByIds(Long[] ids)
    {
        return graduateStudentMapper.deleteGraduateStudentByIds(ids);
    }

    /**
     * 删除代性毕业生信息信息
     * 
     * @param id 代性毕业生信息主键
     * @return 结果
     */
    @Override
    public int deleteGraduateStudentById(Long id)
    {
        return graduateStudentMapper.deleteGraduateStudentById(id);
    }
}
